<template>
    <div class="time-tab">
        <p v-for="(item, index) in timeList" :key="index + 'a'" @click="timeTabFn(item, index)"
            :class="activeIndex == index  ? 'time-tab-active ' : ''">
            {{ item.title }}
        </p>
    </div>
</template>

<script>
export default {
    props: {
        timeList: {
            type: Array,
            default: () => {
                return [
                    {
                        title: '日',
                        value: 0,
                    },
                    {
                        title: '周',
                        value: 1,
                    },
                    {
                        title: '月',
                        value: 2,
                    },
                    {
                        title: '年',
                        value: 3,
                    },
                ]
            }
        }
    },
    data() {
        return {
            activeIndex: 0
        }
    },

    methods: {
        timeTabFn(value, index) {
            this.activeIndex = index
            this.$emit('timeReturnFn', value)
        }
    }
}
</script>

<style lang="less" scoped>
.time-tab {
    display: flex;
    align-items: center;

    p {
        width: 4rem;
        height: 2.8rem;
        opacity: 1;
        border: 1px solid #008EBD;
        font-size: 1.6rem;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #FFFFFF;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        margin-right: 0.5rem;
        cursor: pointer;

        &:last-child {
            margin: 0;
        }
    }

    .time-tab-active {
        background: rgba(0, 214, 251, 0.2);
        border: 1px solid #008EBD;
    }
}
</style>